import axios from 'axios'

const appKey = 'klTPmcG3ayBum6yAuLepu2Xc1dj8WBI2'
const appSecret = 'OXuTJN9TW5VM1CujND8BbJuQrSYfgpom'
const auth = btoa(appKey + ':' + appSecret)

export default (options) => {
  // eslint-disable-next-line no-async-promise-executor
  return new Promise(async (resolve, reject) => {
    try {
      const token = sessionStorage.getItem('accessToken')
      const res = await axios({
        ...options,
        url: '/bimface' + options.url,
        method: options.method || 'post',
        headers: {
          Authorization: token ? 'Bearer ' + token : 'Basic ' + auth
        }
      })

      resolve(res.data.data)
    } catch (error) {
      reject(error)
    }
  })
}
